<!-- saved from url=(0014)about:internet -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>MineSweeper.as</title>
<link rel="stylesheet" type="text/css" href="../../../../SourceStyles.css"/>
</head>

<body><pre><span class="ActionScriptpackage">package</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">mechan</span>.<span class="ActionScriptDefault_Text">samples</span>
<span class="ActionScriptBracket/Brace">{</span>
<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">mechan</span>.<span class="ActionScriptDefault_Text">MecGrid</span>.<span class="ActionScriptDefault_Text">MecGrid</span>;
<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">mechan</span>.<span class="ActionScriptDefault_Text">MecGrid</span>.<span class="ActionScriptDefault_Text">mecGridClasses</span>.<span class="ActionScriptDefault_Text">CellOp</span>;
<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">com</span>.<span class="ActionScriptDefault_Text">mechan</span>.<span class="ActionScriptDefault_Text">MecGrid</span>.<span class="ActionScriptDefault_Text">mecGridClasses</span>.<span class="ActionScriptDefault_Text">HitTestInfo</span>;

<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">display</span>.<span class="ActionScriptDefault_Text">Bitmap</span>;
<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">events</span>.<span class="ActionScriptDefault_Text">EventDispatcher</span>;
<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">flash</span>.<span class="ActionScriptDefault_Text">events</span>.<span class="ActionScriptDefault_Text">MouseEvent</span>;

<span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">mx</span>.<span class="ActionScriptDefault_Text">controls</span>.<span class="ActionScriptDefault_Text">Image</span>;

<span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Event</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">name</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;mineBoomed&quot;</span>, <span class="ActionScriptDefault_Text">type</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;com.mechan.samples.MineSweeperEvent&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
<span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Event</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">name</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;mineMissionCompleted&quot;</span>, <span class="ActionScriptDefault_Text">type</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;com.mechan.samples.MineSweeperEvent&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
<span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Event</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">name</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;mineStateChanged&quot;</span>, <span class="ActionScriptDefault_Text">type</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;com.mechan.samples.MineSweeperEvent&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    
<span class="ActionScriptReserved">public</span> <span class="ActionScriptclass">class</span> <span class="ActionScriptDefault_Text">MineSweeper</span> <span class="ActionScriptReserved">extends</span> <span class="ActionScriptDefault_Text">EventDispatcher</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">MineSweeper</span><span class="ActionScriptBracket/Brace">()</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptDefault_Text">mines</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
        <span class="ActionScriptDefault_Text">shown</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Array</span><span class="ActionScriptBracket/Brace">()</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">set</span> <span class="ActionScriptDefault_Text">MineWidth</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptDefault_Text">gridx</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">value</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">get</span> <span class="ActionScriptDefault_Text">MineWidth</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridx</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">set</span> <span class="ActionScriptDefault_Text">MineHeight</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptDefault_Text">gridy</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">value</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">get</span> <span class="ActionScriptDefault_Text">MineHeight</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">gridy</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">set</span> <span class="ActionScriptDefault_Text">MineSize</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptDefault_Text">maxmines</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">value</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">get</span> <span class="ActionScriptDefault_Text">MineSize</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">maxmines</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">get</span> <span class="ActionScriptDefault_Text">LeftFlags</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">flagsleft</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">mgrid</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MecGrid</span>;
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptReserved">set</span> <span class="ActionScriptDefault_Text">mecGridControl</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MecGrid</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptDefault_Text">mgrid</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">value</span>;
        <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">addEventListener</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">MouseEvent</span>.<span class="ActionScriptDefault_Text">CLICK</span>, <span class="ActionScriptDefault_Text">mouseClickHandler</span><span class="ActionScriptBracket/Brace">)</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[]</span>;
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Array</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[]</span>;
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridx</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">gridy</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">maxmines</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">squaresleft</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">flagsleft</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
    <span class="ActionScriptComment">// private var elapsedtime:;
</span>    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">playing</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">placeflag</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">clicked</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq0.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq0</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq1.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq2.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq3.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq3</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq4.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq4</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq5.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq5</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq6.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq6</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq7.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq7</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sq8.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sq8</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/minered.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">minered</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/nomine.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">nomine</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/mine.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">mine</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sqt0.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sqt0</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sqt1.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sqt1</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptMetadata">Embed</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">source</span><span class="ActionScriptOperator">=</span><span class="ActionScriptString">&quot;/assets/sqt2.gif&quot;</span><span class="ActionScriptBracket/Brace">)]</span>
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sqt2</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Class</span>;
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Object</span>;
    
    <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">StartGame</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
        
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">sqImages</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">null</span><span class="ActionScriptBracket/Brace">)</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptDefault_Text">prepareImages</span><span class="ActionScriptBracket/Brace">()</span>;
        <span class="ActionScriptBracket/Brace">}</span>
        
        <span class="ActionScriptReserved">for</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridy</span>; <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span>, <span class="ActionScriptReserved">false</span><span class="ActionScriptBracket/Brace">]</span>;
            <span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptBracket/Brace">[</span>0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0<span class="ActionScriptBracket/Brace">]</span>;
        <span class="ActionScriptBracket/Brace">}</span>
        
        <span class="ActionScriptComment">// Place the mines, making sure positions are unique
</span>        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">m</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
        
        <span class="ActionScriptReserved">for</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">m</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">m</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">maxmines</span>; <span class="ActionScriptDefault_Text">m</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> 
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">do</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">floor</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">random</span><span class="ActionScriptBracket/Brace">()</span> <span class="ActionScriptOperator">*</span> <span class="ActionScriptDefault_Text">gridx</span><span class="ActionScriptBracket/Brace">)</span>;
                <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">floor</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">Math</span>.<span class="ActionScriptDefault_Text">random</span><span class="ActionScriptBracket/Brace">()</span> <span class="ActionScriptOperator">*</span> <span class="ActionScriptDefault_Text">gridy</span><span class="ActionScriptBracket/Brace">)</span>;
            <span class="ActionScriptBracket/Brace">}</span> <span class="ActionScriptReserved">while</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">])</span>
            
            <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
        <span class="ActionScriptBracket/Brace">}</span>
        
        <span class="ActionScriptComment">// initialize game variables
</span>        <span class="ActionScriptDefault_Text">squaresleft</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gridy</span> <span class="ActionScriptOperator">*</span> <span class="ActionScriptDefault_Text">gridx</span>;
        <span class="ActionScriptDefault_Text">flagsleft</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">maxmines</span>;
        <span class="ActionScriptComment">// elapsedtime = 0;
</span>        <span class="ActionScriptDefault_Text">playing</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
        <span class="ActionScriptDefault_Text">clicked</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>
        <span class="ActionScriptDefault_Text">placeflag</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
        
        <span class="ActionScriptComment">// insert the grid into the document
</span>        <span class="ActionScriptDefault_Text">buildgrid</span><span class="ActionScriptBracket/Brace">()</span>;
        <span class="ActionScriptComment">// Set up keypress handlers
</span>        <span class="ActionScriptComment">// start the clock
</span>    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">prepareImages</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptDefault_Text">sqImages</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Object</span><span class="ActionScriptBracket/Brace">()</span>;
        
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq0&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq0</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq1&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq1</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq2&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq2</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq3&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq3</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq4&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq4</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq5&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq5</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq6&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq6</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq7&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq7</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq8&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sq8</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;minered&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">minered</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;nomine&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">nomine</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;mine&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">mine</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt0&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sqt0</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt1&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sqt1</span><span class="ActionScriptBracket/Brace">())</span>;
        <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt2&quot;</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">sqt2</span><span class="ActionScriptBracket/Brace">())</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">makeImageFromClass</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">s</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Object</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Image</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">img</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Image</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Image</span><span class="ActionScriptBracket/Brace">()</span>;
        <span class="ActionScriptDefault_Text">img</span>.<span class="ActionScriptDefault_Text">source</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">s</span>;
        <span class="ActionScriptDefault_Text">img</span>.<span class="ActionScriptDefault_Text">validateProperties</span><span class="ActionScriptBracket/Brace">()</span>;
        
        <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">img</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">buildgrid</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">mgrid</span><span class="ActionScriptBracket/Brace">)</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">redraw</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
            <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Rows</span>.<span class="ActionScriptDefault_Text">count</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gridy</span>;
            <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Cols</span>.<span class="ActionScriptDefault_Text">count</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">gridx</span>;
            
            <span class="ActionScriptComment">// mgrid.addEventListener(ResizeEvent.RESIZE, resizeGridControl);
</span>            
            <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
            <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">j</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
            
            <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">=</span>0; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Cols</span>.<span class="ActionScriptDefault_Text">count</span>; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Cols</span>.<span class="ActionScriptDefault_Text">item</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">autowidth</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
                <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Cols</span>.<span class="ActionScriptDefault_Text">item</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">width</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt0&quot;</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span>.<span class="ActionScriptDefault_Text">width</span>;
            <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">=</span>0; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Rows</span>.<span class="ActionScriptDefault_Text">count</span>; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Rows</span>.<span class="ActionScriptDefault_Text">item</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">autoheight</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
                <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Rows</span>.<span class="ActionScriptDefault_Text">item</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptBracket/Brace">)</span>.<span class="ActionScriptDefault_Text">height</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt0&quot;</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span>.<span class="ActionScriptDefault_Text">height</span>;
            <span class="ActionScriptBracket/Brace">}</span>
            
            <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">=</span>0; <span class="ActionScriptDefault_Text">i</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Cols</span>.<span class="ActionScriptDefault_Text">count</span>; <span class="ActionScriptDefault_Text">i</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">for</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">j</span><span class="ActionScriptOperator">=</span>0; <span class="ActionScriptDefault_Text">j</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">Rows</span>.<span class="ActionScriptDefault_Text">count</span>; <span class="ActionScriptDefault_Text">j</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span>
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">set_cell</span><span class="ActionScriptBracket/Brace">(C</span><span class="ActionScriptDefault_Text">ellOp</span>.<span class="ActionScriptDefault_Text">IMAGE</span>, <span class="ActionScriptDefault_Text">j</span>, <span class="ActionScriptDefault_Text">i</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Bitmap</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt0&quot;</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span><span class="ActionScriptBracket/Brace">))</span>;
                <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">redraw</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
        <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">setStatus</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> 
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptComment">/*
        document.images.elapse3.src=num[elapsedtime-(Math.floor(elapsedtime/10))*10].src;
        document.images.elapse2.src=num[Math.floor((elapsedtime-(Math.floor(elapsedtime/100))*100)/10)].src;
        document.images.elapse1.src=num[Math.floor(elapsedtime/100)].src;
        document.images.flag3.src=num[flagsleft-(Math.floor(flagsleft/10))*10].src;
        document.images.flag2.src=num[Math.floor((flagsleft-(Math.floor(flagsleft/100))*100)/10)].src;
        document.images.flag1.src=num[Math.floor(flagsleft/100)].src;
        */</span>
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptComment">// Function to calculate the number of mines adjacent to a grid location
</span>    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">surrounding</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> 
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> 0;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridx</span><span class="ActionScriptOperator">-</span>1 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridx</span><span class="ActionScriptOperator">-</span>1 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridy</span><span class="ActionScriptOperator">-</span>1 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridy</span><span class="ActionScriptOperator">-</span>1 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridy</span><span class="ActionScriptOperator">-</span>1 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridx</span><span class="ActionScriptOperator">-</span>1 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">])</span> 
            <span class="ActionScriptDefault_Text">count</span><span class="ActionScriptOperator">++</span>;
            
        <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">count</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptComment">// Recursive function to &apos;roll back&apos; the grid when user clicks on a tile
</span>    <span class="ActionScriptComment">// with no surrounding mines
</span>    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> 
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&gt;=</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridy</span> <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&gt;=</span>0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridx</span><span class="ActionScriptBracket/Brace">)</span> 
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">!=</span> 3<span class="ActionScriptBracket/Brace">)</span> 
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">c</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">surrounding</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span>,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">)</span>;
                <span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> 3;
                <span class="ActionScriptDefault_Text">squaresleft</span><span class="ActionScriptOperator">--</span>;
                
                <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">set_cell</span><span class="ActionScriptBracket/Brace">(C</span><span class="ActionScriptDefault_Text">ellOp</span>.<span class="ActionScriptDefault_Text">IMAGE</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Bitmap</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sq&quot;</span><span class="ActionScriptOperator">+</span><span class="ActionScriptDefault_Text">c</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span><span class="ActionScriptBracket/Brace">))</span>;
                <span class="ActionScriptComment">// document.images[&quot;grd&quot;+y+&quot;_&quot;+x].src = dir + &quot;sq&quot;+c+&quot;.gif&quot;;
</span>                <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">c</span> <span class="ActionScriptOperator">==</span> 0<span class="ActionScriptBracket/Brace">)</span> 
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">-</span>1,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">-</span>1,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">-</span>1,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span>,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span>,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">+</span>1,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">-</span>1<span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">+</span>1,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">)</span>;
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">+</span>1,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">+</span>1<span class="ActionScriptBracket/Brace">)</span>;
                  <span class="ActionScriptBracket/Brace">}</span>
               <span class="ActionScriptBracket/Brace">}</span>
        <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptComment">// Function called when player steps on a mine. All mine locations are uncovered
</span>    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">dead</span><span class="ActionScriptBracket/Brace">()</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> 
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>, <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>;
        
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">notify</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MineSweeperEvent</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">MineSweeperEvent</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">MineSweeperEvent</span>.<span class="ActionScriptDefault_Text">MINE_BOOMED</span><span class="ActionScriptBracket/Brace">)</span>;
        <span class="ActionScriptDefault_Text">dispatchEvent</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">notify</span><span class="ActionScriptBracket/Brace">)</span>;
        
        <span class="ActionScriptReserved">for</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">y</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridy</span>; <span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> 
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">for</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">=</span> 0; <span class="ActionScriptDefault_Text">x</span> <span class="ActionScriptOperator">&lt;</span> <span class="ActionScriptDefault_Text">gridx</span>; <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">++</span><span class="ActionScriptBracket/Brace">)</span> 
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">])</span> 
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">!=</span> 1<span class="ActionScriptBracket/Brace">)</span> 
                    <span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">set_cell</span><span class="ActionScriptBracket/Brace">(C</span><span class="ActionScriptDefault_Text">ellOp</span>.<span class="ActionScriptDefault_Text">IMAGE</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Bitmap</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;mine&quot;</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span><span class="ActionScriptBracket/Brace">))</span>;
                        <span class="ActionScriptComment">// document.images[&quot;grd&quot;+y+&quot;_&quot;+x].src = dir + &quot;mine.gif&quot;;
</span>                       <span class="ActionScriptBracket/Brace">}</span>
                <span class="ActionScriptBracket/Brace">}</span>
                <span class="ActionScriptReserved">else</span> <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">==</span> 1<span class="ActionScriptBracket/Brace">)</span> 
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">set_cell</span><span class="ActionScriptBracket/Brace">(C</span><span class="ActionScriptDefault_Text">ellOp</span>.<span class="ActionScriptDefault_Text">IMAGE</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Bitmap</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;nomine&quot;</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span><span class="ActionScriptBracket/Brace">))</span>;
                    <span class="ActionScriptComment">// document.images[&quot;grd&quot;+y+&quot;_&quot;+x].src = dir + &quot;nomine.gif&quot;;
</span>                  <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptBracket/Brace">}</span>
        <span class="ActionScriptBracket/Brace">}</span>
        
        <span class="ActionScriptComment">// document.images.condition.src = dir + &quot;btndead.gif&quot;;
</span>        <span class="ActionScriptDefault_Text">playing</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
        <span class="ActionScriptDefault_Text">clicked</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptComment">// handler called whenever the grid is clicked
</span>    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">gridclick</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span>, <span class="ActionScriptDefault_Text">x</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span> 
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">playing</span><span class="ActionScriptBracket/Brace">)</span> 
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptDefault_Text">clicked</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
            <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">placeflag</span><span class="ActionScriptBracket/Brace">)</span> 
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">&lt;</span> 3<span class="ActionScriptBracket/Brace">)</span> 
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">s</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">int</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span>;
                    <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">change</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">Boolean</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
                    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">s</span> <span class="ActionScriptOperator">==</span> 1<span class="ActionScriptBracket/Brace">)</span> 
                    <span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptDefault_Text">flagsleft</span><span class="ActionScriptOperator">++</span>;
                        <span class="ActionScriptDefault_Text">squaresleft</span><span class="ActionScriptOperator">++</span>;
                    <span class="ActionScriptBracket/Brace">}</span>
                    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">flagsleft</span> <span class="ActionScriptOperator">==</span> 0 <span class="ActionScriptOperator">&amp;&amp;</span> <span class="ActionScriptDefault_Text">s</span> <span class="ActionScriptOperator">==</span> 0<span class="ActionScriptBracket/Brace">)</span> 
                    <span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptDefault_Text">change</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
                    <span class="ActionScriptBracket/Brace">}</span>
                    <span class="ActionScriptReserved">else</span> 
                    <span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">s</span> <span class="ActionScriptOperator">==</span> 2<span class="ActionScriptBracket/Brace">)</span> 
                            <span class="ActionScriptDefault_Text">s</span> <span class="ActionScriptOperator">=</span> 0;
                        <span class="ActionScriptReserved">else</span> 
                            <span class="ActionScriptDefault_Text">s</span><span class="ActionScriptOperator">++</span>;
                        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">s</span> <span class="ActionScriptOperator">==</span> 1<span class="ActionScriptBracket/Brace">)</span> 
                        <span class="ActionScriptBracket/Brace">{</span>
                            <span class="ActionScriptDefault_Text">flagsleft</span><span class="ActionScriptOperator">--</span>;
                            <span class="ActionScriptDefault_Text">squaresleft</span><span class="ActionScriptOperator">--</span>;
                           <span class="ActionScriptBracket/Brace">}</span>
                    <span class="ActionScriptBracket/Brace">}</span>
                    
                    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">change</span><span class="ActionScriptBracket/Brace">)</span> 
                    <span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">s</span>;
                        <span class="ActionScriptComment">// document.images[&quot;grd&quot;+y+&quot;_&quot;+x].src = dir + &quot;sqt&quot;+s+&quot;.gif&quot;;
</span>                        <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">set_cell</span><span class="ActionScriptBracket/Brace">(C</span><span class="ActionScriptDefault_Text">ellOp</span>.<span class="ActionScriptDefault_Text">IMAGE</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Bitmap</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;sqt&quot;</span> <span class="ActionScriptOperator">+</span> <span class="ActionScriptDefault_Text">s</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span><span class="ActionScriptBracket/Brace">))</span>;
                        <span class="ActionScriptDefault_Text">setStatus</span><span class="ActionScriptBracket/Brace">()</span>;
                    <span class="ActionScriptBracket/Brace">}</span>
                    
                    <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">squaresleft</span> <span class="ActionScriptOperator">==</span> 0<span class="ActionScriptBracket/Brace">)</span> 
                    <span class="ActionScriptBracket/Brace">{</span>
                        <span class="ActionScriptComment">// document.images.condition.src = dir + &quot;btncool.gif&quot;;
</span>                        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">notify</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MineSweeperEvent</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">MineSweeperEvent</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">MineSweeperEvent</span>.<span class="ActionScriptDefault_Text">MINE_MISSION_COMPLETED</span><span class="ActionScriptBracket/Brace">)</span>;
                        <span class="ActionScriptDefault_Text">dispatchEvent</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">notify</span><span class="ActionScriptBracket/Brace">)</span>;
                        <span class="ActionScriptDefault_Text">playing</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
                    <span class="ActionScriptBracket/Brace">}</span>
                <span class="ActionScriptBracket/Brace">}</span>
               <span class="ActionScriptBracket/Brace">}</span>
               <span class="ActionScriptComment">// check not flagged as a mine
</span>            <span class="ActionScriptReserved">else</span> <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">shown</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">]</span> <span class="ActionScriptOperator">!=</span> 1<span class="ActionScriptBracket/Brace">)</span> 
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">mines</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptDefault_Text">y</span><span class="ActionScriptBracket/Brace">][</span><span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">])</span> 
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptComment">// document.images[&quot;grd&quot;+y+&quot;_&quot;+x].src = dir + &quot;minered.gif&quot;;
</span>                    <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">set_cell</span><span class="ActionScriptBracket/Brace">(C</span><span class="ActionScriptDefault_Text">ellOp</span>.<span class="ActionScriptDefault_Text">IMAGE</span>, <span class="ActionScriptDefault_Text">y</span>, <span class="ActionScriptDefault_Text">x</span>, <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">Bitmap</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">sqImages</span><span class="ActionScriptBracket/Brace">[</span><span class="ActionScriptString">&quot;minered&quot;</span><span class="ActionScriptBracket/Brace">]</span>.<span class="ActionScriptDefault_Text">content</span>.<span class="ActionScriptDefault_Text">bitmapData</span><span class="ActionScriptBracket/Brace">))</span>;
                    <span class="ActionScriptDefault_Text">dead</span><span class="ActionScriptBracket/Brace">()</span>;
                <span class="ActionScriptBracket/Brace">}</span>
                <span class="ActionScriptReserved">else</span>  
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptDefault_Text">rollback</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">y</span>,<span class="ActionScriptDefault_Text">x</span><span class="ActionScriptBracket/Brace">)</span>;
                <span class="ActionScriptBracket/Brace">}</span>
              <span class="ActionScriptBracket/Brace">}</span>
              
              <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">notify</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MineSweeperEvent</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">new</span> <span class="ActionScriptDefault_Text">MineSweeperEvent</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">MineSweeperEvent</span>.<span class="ActionScriptDefault_Text">MINE_STATE_CHANGED</span><span class="ActionScriptBracket/Brace">)</span>;
              <span class="ActionScriptDefault_Text">dispatchEvent</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">notify</span><span class="ActionScriptBracket/Brace">)</span>;
        <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptBracket/Brace">}</span>
    
    <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">mouseClickHandler</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">e</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">MouseEvent</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">:</span><span class="ActionScriptReserved">void</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">hit</span><span class="ActionScriptOperator">:</span><span class="ActionScriptDefault_Text">HitTestInfo</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">mgrid</span>.<span class="ActionScriptDefault_Text">HitTest</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">e</span><span class="ActionScriptBracket/Brace">)</span>;
        
        <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">hit</span>.<span class="ActionScriptDefault_Text">type</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptDefault_Text">HitTestInfo</span>.<span class="ActionScriptDefault_Text">HIT_IMAGE</span><span class="ActionScriptBracket/Brace">)</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">e</span>.<span class="ActionScriptDefault_Text">ctrlKey</span> <span class="ActionScriptOperator">==</span> <span class="ActionScriptReserved">true</span><span class="ActionScriptBracket/Brace">)</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">placeflag</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">true</span>;
            <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptReserved">else</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">this</span>.<span class="ActionScriptDefault_Text">placeflag</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptReserved">false</span>;
            <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptDefault_Text">gridclick</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">hit</span>.<span class="ActionScriptDefault_Text">renderer</span>.<span class="ActionScriptDefault_Text">rowIndex</span>, <span class="ActionScriptDefault_Text">hit</span>.<span class="ActionScriptDefault_Text">renderer</span>.<span class="ActionScriptDefault_Text">colIndex</span><span class="ActionScriptBracket/Brace">)</span>;
        <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptBracket/Brace">}</span>
<span class="ActionScriptBracket/Brace">}</span>
<span class="ActionScriptBracket/Brace">}</span></pre></body>
</html>
